import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImports from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import DefineOptions from 'unplugin-vue-define-options/vite'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path')

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src'),
    },
  },
  server: {
    hmr: true,
    proxy: {
      '/api': {
        // target: 'http://127.0.0.1:4523/m1/3451790-0-default',
        target: 'http://s5.v100.vip:4220',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, ''),
      },
      '/get': {
        // target: 'http://127.0.0.1:4523/m1/3451790-0-default',
        target: 'http://127.0.0.1:3000',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/get/, ''),
      },
    },
  },
  plugins: [
    vue(),
    vueJsx(),
    VueSetupExtend(),
    DefineOptions(),
    AutoImports({ resolvers: [ElementPlusResolver()] }),
    Components({ resolvers: [ElementPlusResolver()] }),
  ],
})
